package br.org.isvi.interpretador.portugol.access;

import java.util.HashMap;
import java.util.List;

import org.apache.cayenne.exp.Expression;
import org.apache.cayenne.query.SelectQuery;

import br.org.isvi.interpretador.portugol.model.Aluno;
import br.org.isvi.interpretador.portugol.model.Turma;

public class AlunoDAO extends AbstractDAO<Aluno>{

	@Override
	public Class<Aluno> getType() {
		return Aluno.class;
	}

	@SuppressWarnings("unchecked")
	public Aluno porLogin (String login, Turma turma) {
			List<Aluno> ret;
			HashMap map = new HashMap();
			map.put("loginStr", login);
			map.put("turmaId", turma.getId());
			
			SelectQuery query = new SelectQuery(Aluno.class, Expression.fromString("login like $loginStr and toTurma = $turmaId").
					expWithParameters(map));
			
			ret = getCtx().performQuery(query);
			
			return ret.size()>0? ret.get(0):null;
	}
}
